String.prototype.trim = function(){
    return $.trim(this);
};

String.prototype.format = function(args){
    var str = this;
    var arr = str.match(/\{(\w+)\}/gi);
    for(var i = 0; i < arr.length; i++){
        var l = arr[i].length;
        str = str.replace(arr[i], args[arr[i].substring(1, l - 1)]);
    }
    return str;
};

String.prototype.pad = function(len, flag, type){
    var str = this;
    if(str.length < len){
        while(str.length < len){
            switch(type){
                case 'l':
                    str = flag + str;
                    break;
                case 'r':
                    str = str + flag;
                    break;
                default:
                    str = str + flag;
                    break;
            }
        }
    }
    return str;
};

jQuery.validator.addMethod('character', function(value){
    return /^\w+$/.test(value);
});

jQuery.validator.addMethod('rangeLength', function(value, element, params){
    return value.length >= params[0] && value.length <= params[1];
});

var Soul = {
    extend: function(bc, sc, o) {
        var f = function() {};
        f.prototype = sc.prototype;
        bc.prototype = new f();
        bc.prototype.constructor = bc;
        bc.superclass = sc.prototype;
        for (var m in o){
            bc.prototype[m] = o[m];
        }
    },

    setScope: function(callback, scope) {
        return function() {
            return callback.apply(scope, arguments);
        };
    },

    namespace: function() {
        var ns, d;
        for (var i = 0; i < arguments.length; i++) {
            ns = window;
            d = arguments[i].split(".");
            for (var j in d){
                ns = ns[d[j]] = ns[d[j]] ? ns[d[j]] : {};
            }
        }
    },

    isObject: function(obj) {
        return (obj && obj.constructor && obj.constructor == Object.prototype.constructor && !obj.nodeName)
        ? true : false;
    },

    globals:{
        forms:[],
        grids:[]
    },

    copyright: 'CoderSoul Studio'
};

Soul.Base = function() {
    if (Soul.isObject(arguments[0])) {
        var config = arguments[0];
        Soul.Base.superclass.init.call(this);
        this.initialize(config);
    } else {
        arguments.length > 0?
        Soul.Base.superclass.init.apply(this, arguments):
        Soul.Base.superclass.init.call(this);
    }
};

Soul.extend(Soul.Base, jQuery, {
    initialize: function(config) { }
});